HTMLify
Stock Buy and Sell – Max one Transaction Allowed.py
Views: 27 | Author: prakhardoneria
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class Solution: def maxProfit(self, prices): if not prices: return 0 min_price = float('inf') max_profit = 0 for price in prices: if price < min_price: min_price = price elif price - min_price > max_profit: max_profit = price - min_price return max_profit |